/**
 * @author Vu Nguyen Hoang
 */
$(document).ready(function(){
	$("#countries_list").change(function(){
		$("#zones_list").html('<option value="">Loading</option>');
		$.post("get_zones_for_country.php", {"country_id":this.value}, function(data) {
			if (data == '') {
				$("#zones_list").html('<option value=""><b>No information</b></option>');
				$("#districts_list").html('<option value="">No information</option>');
			} else {
				$("#zones_list").html(data);	
				$.post("get_districts_for_zone.php", {"zone_id":$("#zones_list").attr("value")}, function(data) {
					if (data == '') {
						$("#districts_list").html('<option value=\"\">No information</option>');
					} else {
						$("#districts_list").html(data);			
					}			
				});
			}
		});
	});
	$.post("get_zones_for_country.php", {"country_id":$("#countries_list").attr("value")}, function(data) {
		if (data == '') {
			$("#zones_list").html('<option value=""><b>No information</b></option>');
		} else {
			$("#zones_list").html(data);			
			$.post("get_districts_for_zone.php", {"zone_id":$("#zones_list").attr("value")}, function(data) {
				if (data == '') {
					$("#districts_list").html('<option value=\"\">No information</option>');
				} else {
					$("#districts_list").html(data);			
				}			
			});
		}
	});
	$("#zones_list").change(function(){
		$("#districts_list").html('<option value="">Loading</option>');
		$.post("get_districts_for_zone.php", {"zone_id":this.value}, function(data) {
			if (data == '') {
				$("#districts_list").html('<option value=\"-1\">No information</option>');
		    } else {
				$("#districts_list").html(data);			
			}
		});
	});
	$.post("get_districts_for_zone.php", {"zone_id":$("#zones_list").attr("value")}, function(data) {
		if (data == '') {
			$("#districts_list").html('<option value="">No information</option>');
		} else {
			$("#districts_list").html(data);			
		}			
	});
});

